package com.hnas.trade.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hnas.core.util.StringUtil;
import com.hnas.hnt.orm.EQPInfo;
import com.hnas.hnt.orm.Mrch;
import com.hnas.hnt.service.IIndustryService;
import com.hnas.hnt.service.IMrchService;
import com.hnas.trade.service.UpdateCoreTradeTaskService;
import com.hnas.trade.service.dto.DTOResultTransApp;

@Controller
@RequestMapping("/backend/mrch")
public class MrchInfoController {

	@Autowired
	private IIndustryService industryService;
	
	@Autowired
	private IMrchService mrchService;
	
	@Autowired
	private UpdateCoreTradeTaskService updateCoreTradeTaskService;
	
	public List<Mrch> mrchs = new ArrayList<Mrch>();
	/**
	 * 同步当天
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@RequestMapping("/syncCoreTranOrderRecord")
	@ResponseBody
	public String DoFinalTest(String startDate){
		updateCoreTradeTaskService.SyncCoreTranOrderRecord(startDate, startDate);
		return "操作完成！";
	}
	/**
	 * 同步一段时间
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@RequestMapping("/syncCoreTranOrderRecord2")
	@ResponseBody
	public String DoFinalTest2(String startDate,String endDate){
		updateCoreTradeTaskService.SyncCoreTranOrderRecord2(startDate, endDate);
		return "操作完成！";
	}
	
	
	
	/**
	 * 同步当天
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@RequestMapping("/TestGetSql")
	@ResponseBody
	public String TestGetSql(String startDate,String endDate){
//		updateCoreTradeTaskService.getTradeByOld3("123456", startDate, startDate);
		updateCoreTradeTaskService.SyncCoreTranOrderRecord3(startDate, endDate);
		return "操作完成！";
	}
	
	@RequestMapping("/getTradeByCardNo")
	@ResponseBody
	public List<DTOResultTransApp> getTradeByCardNo(String cardNo,String startDate,String endDate){
		return updateCoreTradeTaskService.getTradeByCardNo1(cardNo, startDate, endDate);
	}
	
	
	/**
	 * 查商家
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "getMrchs")
	@ResponseBody
	public List<Mrch> getMrchs(HttpServletRequest request, HttpServletResponse response) {
		return mrchs;
	}
	
	/**
	 * 终端号
	 * 
	 * @param request
	 * @param response
	 * @param mrchId
	 */
	@RequestMapping(value = "getTerminalNo")
	@ResponseBody
	public List<EQPInfo> getTerminalNo(HttpServletRequest request, HttpServletResponse response, String mrchId) {
		List<EQPInfo> list = new ArrayList<EQPInfo>();
		try {
			if(StringUtil.isNotEmpty(mrchId)){
				list = this.mrchService.getEQPsByMrchId(mrchId);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
}
